// import { log } from "numeric";
import { Engine } from "../Engine";
import { any } from "../core/logic";
import { Component, ComponentType } from "./Component";
/**
 * @memberof w.component
 */
class Script extends Component {
  constructor(opts = {}) {
    opts.type = any(opts.type, ComponentType.Script);
    super(opts);
    this.context = {};
    this.behavior = any(opts.behavior, "click");
    this.handler = opts.handler;
  }
  set handler(v) {
    this._handler = v;
    return this;
  }
  get handler() {
    return this._handler;
  }
  addcontext(name, v) {
    if (!this.context.hasOwnProperty(name)) {
      this.context[name] = v;
    }
  }
  onScript(info) {
    let script = this.handler;
    if (script) {
      new Function("info", "w","instanceIndex", "engine", "scene", "context", `${script}`)(
        info,
        w,
        info?.instanceIndex,
        Engine.instance,
        Engine.instance.scene,
        this.context
      );
    }
  }
}
export { Script };

// let s=new w.component.Script();
// s.handler=`info.mesh.material.color= '#ff0000'`;
// entity1.addComponent(s);
